<template>
  <div class="table-page">
    <GiTable
      row-key="id"
      title="参会企业列表"
      :data="dataList"
      :columns="columns"
      :loading="loading"
      :scroll="{ x: '100%', y: '100%', minWidth: 1000 }"
      :pagination="pagination"
      :disabled-tools="['size']"
      :disabled-column-keys="['name']"
      @refresh="search"
    >
      <template #custom-left>
	        <a-input v-model="queryForm.name" placeholder="请输入企业名称" allow-clear @change="search">
	          <template #prefix><icon-search /></template>
	        </a-input>
	        <a-input v-model="queryForm.industry" placeholder="请输入行业类型" allow-clear @change="search">
	          <template #prefix><icon-search /></template>
	        </a-input>
        <a-button @click="reset">重置</a-button>
      </template>
      <template #status="{ record }">
        <a-tag v-if="record.status === 0" color="green">已审核</a-tag>
        <a-tag v-if="record.status === 1" color="orange">未审核</a-tag>
        <a-tag v-if="record.status === 2" color="red">审核失败</a-tag>
      </template>
      <template #action="{ record }">
        <a-space>
          <a-link @click="searchPost(record.id)">查看岗位</a-link>
        </a-space>
      </template>
    </GiTable>
  </div>
</template>

<script setup lang="ts">
import {type CompanyQuery, listCompany, listCompanyByJobfairId} from '@/apis'
import type { TableInstanceColumns } from '@/components/GiTable/type'
import { useTable } from '@/hooks'
import { isMobile } from '@/utils'
import has from '@/utils/has'
import router from "@/router";

defineOptions({ name: 'Company' })

const route = useRoute();
const jobfairId = route.query.jobfairId// 获取传递的 id

const queryForm = reactive<CompanyQuery>({
  id: jobfairId as any,
  name: "",
  industry: "",
  status: "",
  sort: ['createTime,desc']
})


const {
  tableData: dataList,
  loading,
  pagination,
  search,
} = useTable((page) => listCompanyByJobfairId(queryForm.id), { immediate: true })

const columns: TableInstanceColumns[] = [
  { title: '企业名称', dataIndex: 'name', slotName: 'name' },
  { title: '行业类型', dataIndex: 'industry', slotName: 'industry' },
  { title: '公司地址', dataIndex: 'location', slotName: 'location' },
  { title: '网站地址', dataIndex: 'website', slotName: 'website' },
  {
    title: '操作',
    slotName: 'action',
    width: 130,
    align: 'center',
    fixed: !isMobile() ? 'right' : undefined,
  }
]

// 重置
const reset = () => {
  queryForm.name = ""
  queryForm.industry = ""
  search()
}

// 查看参会企业岗位
const searchPost = async (companyId: string) => {
  router.push({
    path: '/jobfairCompanyPost',
    query: {jobfairId: queryForm.id, companyId: companyId }
  })
}
</script>

<style lang="scss" scoped></style>
